package com.rongcheng.fortestlist;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.rongcheng.fortestlist.EXELFrameworkDemo.ExElQAActivity;
import com.rongcheng.fortestlist.LifeStyle.LifeStyleActivity;
import com.rongcheng.fortestlist.crashHandler.CrashActivity;
import com.rongcheng.fortestlist.model.MainListModel;
import com.rongcheng.fortestlist.view.ViewActivity;
import com.rongcheng.fortestlist.viewPager.ViewPagerTestActivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    android.support.v7.widget.RecyclerView recycler_view;
    private List<MainListModel> listModels = new ArrayList<>();
    private List<String> itemNames = new ArrayList<>();
    private MainRecyclerViewAdapter mMainRecyclerViewAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        setMainRecyclerView();
        mMainRecyclerViewAdapter.update(listModels);
        mMainRecyclerViewAdapter.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onRecyclerViewItemClick(View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(MainActivity.this, ViewPagerTestActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MainActivity.this, CrashActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(MainActivity.this, ViewActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(MainActivity.this, LifeStyleActivity.class));
                        break;
                    case 4:
                        startActivity(new Intent(MainActivity.this, ExElQAActivity.class));
                        break;
                }
            }
        });
    }

    private void setMainRecyclerView() {
        recycler_view = (RecyclerView) findViewById(R.id.recycler_view);
        mMainRecyclerViewAdapter = new MainRecyclerViewAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycler_view.setLayoutManager(linearLayoutManager);
        recycler_view.addItemDecoration(new SimplePaddingDecoration(this, 5, R.color.colorPrimary, 0, 0));
        recycler_view.setAdapter(mMainRecyclerViewAdapter);
    }

    private void initData() {
        itemNames = Arrays.asList(getResources().getStringArray(R.array.main_list));
        for (int i = 0; i < itemNames.size(); i++) {
            MainListModel mainListModel = new MainListModel();
            mainListModel.setItemName(itemNames.get(i));
            listModels.add(mainListModel);
        }
    }
}
